/*
 * User: user
 * Date: 21/12/2007
 * Time: 00:53:33
 */
package org.conann.metadata.validation;

import static com.google.common.base.Preconditions.checkNotNull;
import org.conann.metadata.records.MethodRecord;

import javax.webbeans.scope.Dependent;
import java.lang.reflect.Method;
import static java.lang.reflect.Modifier.isFinal;

public class MethodValidator extends RecordValidator<MethodRecord> {

    @Override
    public void validate (MethodRecord record) {
        checkNotNull(record);
        validateDependentScope(record);
    }

    private void validateDependentScope (MethodRecord record) {
        final Method method = record.getMethod();
        if (isFinal(method.getModifiers())) {
            check(record.isAnnotatedBy(Dependent.class), "{0} has a final method {1} and and should be annotated with @{2}", method.getDeclaringClass(), method, Dependent.class.getSimpleName());
        }
    }
}